const path = require('path');
const webpack = require('webpack');
const webpackBaseConfig = require("./config/base.js");
const webpackMerge = require('webpack-merge');
const OpenBrowserPlugin = require('open-browser-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = function() {
  return webpackMerge(webpackBaseConfig(), {
    entry: {
      app: './app/index.js',
      vendors: './app/vendor.js'
    },
    devtool: "source-map",
    output: {
      filename: '[name]-[hash].js',
      path: path.resolve(__dirname, 'dist/'),
      chunkFilename: 'test',
      library: 'libray',
      publicPath: '' //此处是打包是替换路径的
    },
    module: {
      rules: [
       {
          test: /\.scss$/,
          use: ExtractTextPlugin.extract({
            use: [
              {
                loader: "css-loader", //解析css代码
                options: {
                  minimize: true, //压缩代码
                  sourceMap: true //提供代码映射图
                }
              }, {
                loader: "sass-loader"
              }
            ],
            fallback: 'style-loader', //将css代码嵌入到JavaScript
          })
        }
      ]
    },
    devServer: {
      contentBase: './dist',
      port: 8080,
      inline: true,
      hot: true,
      compress: true, //进行gzip压缩
      historyApiFallback: true
    },
    plugins: [
      new OpenBrowserPlugin({url: 'http://localhost:8080'})
    ]
  });
}
